using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TypeAndRun
{
    public partial class ConfigForm : Form
    {
        private Setting setting;
        public ConfigForm()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            setting = new Setting("setting.txt");
            string hk = setting.GetValueByKey("Display_HK");
            if (hk.Length>=2)
            {
                textBox1.Text = hk[1].ToString();
            }
        }

        private void listBox1_Click(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;
            if (index == 1)
            {
                panel_config.Hide();
                panel_hotkey.Show();
            }
            else if (index==2)
            {
                panel_config.Show();
                panel_hotkey.Hide();
            }
        }

        private void ConfigForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Hide();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int flag = (radioButton1.Checked == true) ? 1 : 0;
            flag = (radioButton2.Checked == true) ? 2 : flag;
            flag = (radioButton3.Checked == true) ? 3 : flag;
            flag = (radioButton4.Checked == true) ? 4 : flag;
            if (textBox1.Text.ToString().Trim().Length < 1)
            {
                return;
            }
            char Key = textBox1.Text.ToString().ToUpper()[0];
            if (Key >= 'A' || Key <= 'Z')
            {
            }
            else
            {
                MessageBox.Show("please enter a character");
                return;
            }
            setting.AddCommand("Display_HK", flag.ToString() + Key.ToString());
            setting.Save();
            this.Hide();
        }
    }
}